package com.ruoyi.system.controller;

import com.ruoyi.argument.CurrentUser;
import com.ruoyi.dto.DataWrapper;
import com.ruoyi.system.domain.Student;
import com.ruoyi.system.domain.StudentLeave;
import com.ruoyi.system.service.StudentLeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 请假记录Controller
 *
 * @author ruoyi
 * @date 2023-03-29
 */
@Controller
@RequestMapping("/studentLeave")
public class StudentLeaveController{

    @Autowired
    private StudentLeaveService studentLeaveService;


    @PostMapping("/list")
    @ResponseBody
    public DataWrapper<List<StudentLeave>> list(@CurrentUser Student student) {
        List<StudentLeave> list = studentLeaveService.selectStudentLeave(student.getStudentId());
        return DataWrapper.success(list);
    }

    @PostMapping("/submit")
    @ResponseBody
    public DataWrapper<String> submit(@RequestBody StudentLeave studentLeave, @CurrentUser Student student) {
        studentLeave.setStudentId(student.getStudentId());
        studentLeave.setState(0L);
        studentLeaveService.submit(studentLeave);
        return DataWrapper.success();
    }

}
